package com.hawthorn.admin.controller.appuser;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hawthorn.admin.service.appuser.AppUserService;
import com.hawthorn.platform.annotation.MarkLog;
import com.hawthorn.platform.exception.BizCode;
import com.hawthorn.platform.utils.common.MyUtil;
import com.hawthorn.platform.utils.iassert.AssertMyUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * <p>todo APP用户controller</p>
 * @author: sunwanzhong
–
 * @created: 2023/2/14 21:38
 * @version v1.0.1
 * @copyright: Copyright (c) 2023 sunwanzhong
 */
@Api(tags = {"admin-appuser"})
@RestController
@RequestMapping("/appuser/")
@Slf4j
public class AppUserController
{
  @Resource
  AppUserService appUserService;

  @ApiOperation(value = "保存->保存app用户信息", notes = "插入app用户信息")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "params", value = "保存参数", dataTypeClass = Map.class)
  })
  @MarkLog(value = "新增app用户-[{0}]", param = "account")
  @PostMapping(value = "/saveAppUser")
  public Map<String, Object> saveAppUser(@RequestBody Map<String, Object> param)
  {
    return appUserService.saveAppUser(param);
  }

  /**
   * <p>todo 修改app用户手机号</p>
   * @author: sunwanzhong
   * @date: 2023/3/6 19:39
   * @version: 1.0.1
   */
  @ApiOperation(value = "修改->修改app用户手机号", notes = "修改app用户手机号")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "params", value = "保存参数", dataTypeClass = Map.class)
  })
  @MarkLog(value = "修改app用户手机号-[{0}]", param = "account")
  @PostMapping(value = "/updateAppUserPhone")
  public Map<String, Object> updateAppUserPhone(@RequestBody Map<String, Object> param)
  {
    return appUserService.updateAppUserPhone(param);
  }

  /**
   * <p>todo 修改app用户信息</p>
   * @author: sunwanzhong
   * @date: 2023/3/18 14:00
   * @version: 1.0.1
   */
  @ApiOperation(value = "修改->修改app用户信息", notes = "修改app用户信息")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "params", value = "保存参数", dataTypeClass = Map.class)
  })
  @MarkLog(value = "修改app用户信息-[{0}]", param = "account")
  @PostMapping(value = "/updateAppUserInfo")
  public void updateAppUserInfo(@RequestBody Map<String, Object> param)
  {
    appUserService.updateAppUserInfo(param);
  }

  /**
   * <p>todo 查询app用户手机号是否存在</p>
   * @author: sunwanzhong
   * @date: 2023/5/8 9:50
   * @version: 1.0.1
   */
  @ApiOperation(value = "查询->查询app用户手机号是否存在", notes = "查询app用户手机号是否存在")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "param", value = "param", dataTypeClass = String.class)
  })
  @MarkLog(value = "查询app用户手机号是否存在-[{0}]", param = "account")
  @PostMapping(value = "/findIsExist")
  public Map<String, Object> findIsExist(@RequestBody Map<String, Object> param)
  {
    return appUserService.findIsExist(param);
  }

  /**
   * <p> todo app用户查询
   * @param:
   * @param: null
   * @return: {@link null}
   * @author: yumiaoting <br>
   * @date: 2023/2/21 10:29 <br>
   * @version: 1.0.1
   * Modification History:
   * Date   Author   Version   Description
   * -----------------------------------------------------------
   * 2023/2/21   yumiaoting   1.0.1
   */
  @ApiOperation(value = "查询->app用户查询-查询列表", notes = "查询列表")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "params", value = "查询条件参数", dataTypeClass = String.class)
  })
  @PostMapping(value = "/findAppUser")
  public IPage<Map<String, Object>> findAppUser(@RequestBody String params)
  {
    Page<Map<String, Object>> page = new Page<>();
    String conditions = MyUtil.getConditionsWhere(params, page);
    return appUserService.findAppUser(page, conditions);
  }

  /**
   * <p>todo 删除app用户</p>
   * @author: sunwanzhong
   * @date: 2023/5/4 18:00
   * @version: 1.0.1
   */
  @ApiOperation(value = "删除app用户-[{0}]", notes = "删除app用户")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "id", value = "id", dataTypeClass = Long.class)
  })
  @PostMapping(value = "/delAppUser/{id}")
  public void delAppUser(@PathVariable("id") String id)
  {
    appUserService.delAppUser(id);
  }

  /**
   * <p> todo 导出app用户
   * @param:
   * @param: null
   * @return: {@link null}
   * @author: yumiaoting <br>
   * @date: 2023/2/21 11:49 <br>
   * @version: 1.0.1
   * Modification History:
   * Date   Author   Version   Description
   * -----------------------------------------------------------
   * 2023/2/21   yumiaoting   1.0.1
   */
  @ApiOperation(value = "导出->app用户", notes = "导出app用户")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "response", value = "response", dataTypeClass = HttpServletResponse.class),
      @ApiImplicitParam(name = "params", value = "params", dataTypeClass = String.class)
  })
  @PostMapping(value = "/exportAppUser")
  public void export(HttpServletResponse response, @RequestBody Map<String, Object> param) throws IOException
  {
    AssertMyUtil.notNull(param, BizCode.VARIABLE_NOT_EMPTY, "param");
    appUserService.exportAppUser(response, "app用户导出数据", param);
  }
}
